package c.f.d.a.a.b;

import c.f.a.a.a.a;
import java.io.IOException;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.X509TrustManager;
import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.StrictHostnameVerifier;

public class b extends SSLSocketFactory {
    public static final String c = b.class.getSimpleName();
    public SSLContext a;
    public SSLSocket b = null;

    static {
        BrowserCompatHostnameVerifier browserCompatHostnameVerifier = new BrowserCompatHostnameVerifier();
        StrictHostnameVerifier strictHostnameVerifier = new StrictHostnameVerifier();
    }

    public b(KeyStore keyStore, X509TrustManager x509TrustManager) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException, IllegalArgumentException {
        super(null);
        SSLContext d = a.d();
        this.a = d;
        d.init(null, new X509TrustManager[]{x509TrustManager}, null);
    }

    public final void a(Socket socket) {
        Object obj;
        Object obj2 = null;
        if (a.d(null)) {
            obj = null;
        } else {
            a.h(c, "set protocols");
            a.c((SSLSocket) socket, null);
            obj = 1;
        }
        if (!(a.d(null) && a.d(null))) {
            a.h(c, "set white cipher or black cipher");
            SSLSocket sSLSocket = (SSLSocket) socket;
            a.b(sSLSocket);
            if (a.d(null)) {
                a.a(sSLSocket, null);
            } else {
                a.e(sSLSocket, null);
            }
            obj2 = 1;
        }
        if (obj == null) {
            a.h(c, "set default protocols");
            a.b((SSLSocket) socket);
        }
        if (obj2 == null) {
            a.h(c, "set default cipher suites");
            SSLSocket sSLSocket2 = (SSLSocket) socket;
            if (sSLSocket2 != null && !a.e(sSLSocket2, a.b)) {
                a.a(sSLSocket2, a.c);
            }
        }
    }

    public Socket createSocket(Socket socket, String str, int i, boolean z) throws IOException {
        a.h(c, "createSocket: socket host port autoClose");
        socket = this.a.getSocketFactory().createSocket(socket, str, i, z);
        if (socket instanceof SSLSocket) {
            a(socket);
            SSLSocket sSLSocket = (SSLSocket) socket;
            this.b = sSLSocket;
            sSLSocket.getEnabledCipherSuites().clone();
        }
        return socket;
    }

    public Socket createSocket() throws IOException {
        a.h(c, "createSocket: ");
        Socket createSocket = this.a.getSocketFactory().createSocket();
        if (createSocket instanceof SSLSocket) {
            a(createSocket);
            SSLSocket sSLSocket = (SSLSocket) createSocket;
            this.b = sSLSocket;
            sSLSocket.getEnabledCipherSuites().clone();
        }
        return createSocket;
    }
}
